package com.wanlian.router.ui.manage;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.smart.android.ui.BaseActivity;
import com.wanlian.router.R;
import com.wanlian.router.bean.RouterSetting;
import com.wanlian.router.net.NetWorkingClient;
import com.wanlian.router.net.ResponseData;
import com.wanlian.router.net.internal.INetCallBack;

import java.util.Locale;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Hyu on 2018/8/30.
 * Email: fvaryu@163.com
 */
public class RouterSettingActivity extends BaseActivity {


    @BindView(R.id.tv_version)
    TextView tv_version;
    @BindView(R.id.tv_blacklist_count)
    TextView tv_blacklist_count;
    @BindView(R.id.tv_share_disk_cout)
    TextView tv_share_disk_cout;
    @BindView(R.id.tv_net)
    TextView tv_net;

    @Override
    protected int layout() {
        return R.layout.activity_router_setting;
    }

    @Override
    public void initUI() {
        super.initUI();
        setTitle("设置");
    }

    @Override
    public void initData() {
        super.initData();


    }

    @Override
    protected void onResume() {
        super.onResume();
        NetWorkingClient.getInstance().queryRouterSetting(getActivity(), new INetCallBack<RouterSetting>() {
            @Override
            public void onFinish(ResponseData response, @Nullable RouterSetting routerSetting) {
                if (response.isSuccess()) {

                    if (routerSetting == null) {
                        return;
                    }
                    tv_net.setText(routerSetting.getStatic_ip());
                    tv_version.setText(routerSetting.getVersion());
                    tv_blacklist_count.setText(String.format(Locale.getDefault(),"%s台设备", routerSetting.getBlackcount()));
                    tv_share_disk_cout.setText(routerSetting.getSharedisk());

                    if ("未设置".equals(routerSetting.getSharedisk())) {
                        tv_share_disk_cout.setTextColor(getColorById(R.color.color_red));
                    }else {
                        tv_share_disk_cout.setTextColor(getColorById(R.color.color_99));
                    }
                    tv_share_disk_cout.setText(routerSetting.getSharedisk());

                }else {
                    showToast(response.getMessage());
                }
            }
        });
    }

    @OnClick(R.id.tv_networking_setting)
    void networking() {
        redirectActivity(NetworkingSettingActivity.class);
    }


    @OnClick(R.id.tv_blacklist)
    void blacklist() {
        redirectActivity(BlacklistActivity.class);
    }

    @OnClick(R.id.tv_wifi)
    void wifi() {
        redirectActivity(WifiSettingActivity.class);
    }

    @OnClick(R.id.tv_networking_device)
    void device() {
        redirectActivity(NetworkingDeviceActivity.class);
    }

    @OnClick(R.id.tv_share_disk)
    void shareDisk() {
        redirectActivity(ShareDiskManageActivity.class);
    }
}
